package com.clp.protocol.iec104.iec104.client;

import com.clp.protocol.iec104.iec104.apdu.Apdu;

public class InMasterApduSendHandler {
    private final InMaster inMaster;

    public InMasterApduSendHandler(InMaster inMaster) {
        this.inMaster = inMaster;
    }

    // 检查和更新所有状态
    public Apdu handleSending(Apdu apdu) {
        // 更新主站状态
        apdu = inMaster.stateInfo().updateStateBySending(apdu);
        if (apdu == null) return null;
        // 发送前处理：更新序号
        if (apdu.isIType()) {
            inMaster.addSendSeqCircularly();
        }
        return apdu;
    }
}
